<?php
// +----------------------------------------------------------------------
// | sfadmin - Suifeng Administration
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://suifeng.tech All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: suifeng <1787585212@qq.com>
// +----------------------------------------------------------------------

namespace suifeng\helper;

abstract class BaseObject
{
    /**
     * 配置数组，通过构造器传过来的。
     *
     * @var array
     */
    protected $_config = array();

    /**
     * 构造方法。
     *
     * @param array $config
     */
    public function __construct($config = array())
    {
        $this->merge_config($config);
    }

    /**
     * 合并配置信息。
     *
     * @param array $config
     */
    public function merge_config($config)
    {
        $this->_config = $config;
        $vars = get_object_vars($this);

        foreach ($config as $key => $value) {
            $method_name = '_init_' . $key;
            if (method_exists($this, $method_name)) {
                $this->$method_name($value);
            } else if (array_key_exists($key, $vars)) {
                $this->$key = $value;
            }
        }
    }
}

?>